﻿using AutoMapper;
using IoTAdapter.BaseCore.Enums;
using Warehouse.Entites;
using Warehouse.ViewModels.TESinterfaceDTO;
using WCS.Entities;
using WCS.ViewModels;
using static Npgsql.Replication.PgOutput.Messages.RelationMessage;

namespace WCS.API.Tools
{
    /// <summary>
    /// mapper
    /// </summary>
    public class CustomAutoMapperProfile : Profile
    {
        /// <summary>
        /// 重构
        /// </summary>
        public CustomAutoMapperProfile()
        {

            #region Device

            CreateMap<Device, DeviceDto>()
             .ForMember(dest => dest.Type, source => source.MapFrom(src => Enum.GetName(src.Type)));

            CreateMap<DeviceDto, Device>()
              .ForMember(dest => dest.Type, source => source.MapFrom(src => (EthernetDeviceVersion)Enum.Parse(typeof(EthernetDeviceVersion), src.Type)));

            #endregion

            #region 料口信息
            CreateMap<TransferPort, PortDto>().
                ForMember(dest => dest.DeviceIP, src => src.MapFrom(x => x.BelongDevice.IP));

            CreateMap<PortDto, TransferPort>();
            CreateMap<TransferPort, PortShowDto>().ForMember(dest => dest.IP, source => source.MapFrom(src => src.BelongDevice.IP)).
                ForMember(dest => dest.Type, source => source.MapFrom(src => src.BelongDevice.Type.ToString())).
                ForMember(dest => dest.CallType, source => source.MapFrom(src => src.CallType.GetDescription())).
                ForMember(dest => dest.Enable, source => source.MapFrom(src => src.BelongDevice.Enable)).
                ForMember(dest => dest.IsConnected, source => source.MapFrom(src => src.BelongDevice.IsConnected));
            #endregion



            CreateMap<SystemParameter, ParameterDto>().ForMember(dest => dest.AvailableStatus, source => source.MapFrom(src => string.Join(',', src.AvailableStatus)));
            CreateMap<ParameterDto, SystemParameter>().ForMember(dest => dest.AvailableStatus, source => source.MapFrom(src => src.AvailableStatus.Split(',', StringSplitOptions.RemoveEmptyEntries).ToList()));

            CreateMap<HandlingCompletedDTO, Handling>()
               .ForMember(dest => dest.podID, opt => opt.MapFrom(src => src.content.podID))
               .ForMember(dest => dest.status, opt => opt.MapFrom(src => src.content.status))
               .ForMember(dest => dest.taskID, opt => opt.MapFrom(src => src.content.taskID))
               .ForMember(dest => dest.bizID, opt => opt.MapFrom(src => src.content.bizID))
               .ForMember(dest => dest.errorCode, opt => opt.MapFrom(src => src.content.errorCode))
               .ForMember(dest => dest.errorReason, opt => opt.MapFrom(src => src.content.errorReason))
               .ForMember(dest => dest.desType, opt => opt.MapFrom(src => src.content.desType))
               .ForMember(dest => dest.desNodeID, opt => opt.MapFrom(src => src.content.desNodeID))
               .ForMember(dest => dest.desBasketID, opt => opt.MapFrom(src => src.content.desBasketID))
               .ForMember(dest => dest.desStoragID, opt => opt.MapFrom(src => src.content.desStoragID))
               .ForMember(dest => dest.desZoneCode, opt => opt.MapFrom(src => src.content.desZoneCode))
               .ForMember(dest => dest.messageType, opt => opt.MapFrom(src => src.messageType))
               .ForMember(dest => dest.message, opt => opt.MapFrom(src => src.message))
               .ForMember(dest => dest.warehouseID, opt => opt.MapFrom(src => src.warehouseID)
               ); //以此类推,把每一个需要的字段，映射一下
           // CreateMap<SiteReleaseDTO, Siterelease>()
           //     .ForMember(dest => dest.messageType, opt => opt.MapFrom(src => src.messageType))
           //     //.ForMember(dest => dest.stationCode, opt => opt.MapFrom(src => src.stationCode))
           //     //.ForMember(dest => dest.podID, opt => opt.MapFrom(src => src.podID))
           //     //.ForMember(dest => dest.occupyStatus, opt => opt.MapFrom(src => src.occupyStatus))
           //     ;
           //;
        }

    }
}
